package com.atguigu.day03;

import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.connector.file.src.FileSource;
import org.apache.flink.connector.file.src.reader.TextLineInputFormat;
import org.apache.flink.core.fs.Path;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author Felix
 * @date 2024/4/1
 * 该案例演示了从指定的文件中读取数据
 */
public class Flink05_Source_File {
    public static void main(String[] args) throws Exception {
        //TODO 1.指定流处理环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        //从指定的文件中读取数据
        //DataStreamSource<String> fileDS = env.readTextFile("D:\\dev\\workspace\\bigdata-1030\\input\\word.txt");

        FileSource<String> source = FileSource
                .forRecordStreamFormat(new TextLineInputFormat(), new Path("D:\\dev\\workspace\\bigdata-1030\\input\\word.txt")).build();

        //将指定的数据源封装为流
        //flink1.12前
        //env.addSource();
        //flink1.12后
        DataStreamSource<String> fileDS = env.fromSource(source, WatermarkStrategy.noWatermarks(), "file_source");

        fileDS.print();

        env.execute();
    }
}
